package xcmg.device.web.iteration;

import com.alibaba.fastjson.JSONArray;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import xcmg.device.dao.entity.SysIterationTip;
import xcmg.device.infra.BasicController;
import xcmg.device.service.crm.util.ActionResultUtil;
import xcmg.device.service.sysIteration.SysIterationService;
import xcmg.device.service.vo.sysIteration.SysIterationTipVO;
import yb.ecp.fast.infra.infra.ActionResult;

import java.util.Collections;
import java.util.List;

@RestController
@RequestMapping("/sysIteration")
public class SysIterationController extends BasicController {
    @Autowired
    private SysIterationService sysIterationService;

    @RequestMapping(value="tip",method = {RequestMethod.POST, RequestMethod.GET})
    public ActionResult tip(){
        SysIterationTip sysIdentifyTip = sysIterationService.getLastEffictiveTip();
        if(sysIdentifyTip == null){
            return ActionResultUtil.successActionResult();
        }
        SysIterationTipVO result = new SysIterationTipVO();
        String iterateContents = sysIdentifyTip.getIterateContents();
        List<String> iterateContentsLst = StringUtils.isEmpty(iterateContents) ? Collections.EMPTY_LIST : JSONArray.parseArray(iterateContents, String.class);
        result.setIterateContents(iterateContentsLst);
        result.setIterateTime(sysIdentifyTip.getIterateTime());
        String iterateScopes = sysIdentifyTip.getIterateScopes();
        List iterateScopesLst = StringUtils.isEmpty(iterateScopes) ? Collections.EMPTY_LIST : JSONArray.parseArray(iterateScopes, String.class);
        result.setIterateScopes(iterateScopesLst);
        return ActionResultUtil.successActionResult(result);
    }
}
